package com.prd.controller;


import com.prd.dto.AttendanceSettingDTO;
import com.prd.model.AttendanceSettingDO;
import com.prd.service.AttendanceSettingService;
import com.prd.util.CommonUtil;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 考勤设置表 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2023-12-04
 */
@RestController
@RequestMapping("/api/attendanceSetting")
@Api(tags = "考勤设置")
public class AttendanceSettingController {

    @Autowired
    private AttendanceSettingService attendanceSettingService;

    @ApiOperation("获取考勤设置参数")
    @GetMapping("getSetting")
    public JsonData getSetting (){
        return JsonData.buildSuccess(attendanceSettingService.list());
    }

    @ApiOperation("设置考勤参数")
    @PostMapping("setClockInAddress")
    public JsonData setClockInAddress (@RequestBody AttendanceSettingDTO dto){
        boolean update = attendanceSettingService.saveOrUpdate(CommonUtil.dtoTransfer(dto,AttendanceSettingDO.class));
        if (!update) {
            return JsonData.buildError("设置考勤参数异常");
        }
        return JsonData.buildSuccess();
    }

}

